// GetNeighbors.h
#ifndef GETNEIGHBORS_H
#define GETNEIGHBORS_H

#include "../core/DoublyLinkedList.h"
#include <iostream>
using namespace std;

class NeighborFinder {
public:
    static void findNeighbors(DoublyLinkedList& dll, int position) {
        if (position <= 0) {
            cout << "位置必须为正整数！" << endl;
            return;
        }
        
        listNode* current = dll.getNodeAt(position);
        
        if (current == nullptr) {
            cout << "位置 " << position << " 超出链表长度！" << endl;
            cout << "当前链表长度为: " << dll.getLength() << endl;
            return;
        }
        
        cout << "第 " << position << " 个节点: " << current->data << endl;
        
        if (current->prev != nullptr) {
            cout << "前驱节点: " << current->prev->data << endl;
        } else {
            cout << "前驱节点: 无 (这是头节点)" << endl;
        }
        
        if (current->next != nullptr) {
            cout << "后继节点: " << current->next->data << endl;
        } else {
            cout << "后继节点: 无 (这是尾节点)" << endl;
        }
    }
};

#endif